<?php $this->beginBlock('title');?>
    网站设置
<?php $this->endBlock();?>
<?php $this->beginBlock('headerCssFile')?>
    <link rel="stylesheet" type="text/css" href="/plugins/layui/css/layui.css">
<?php $this->endBlock()?>
<?php $this->params['breadcrumbs'] =
    [
        [
            'label' => '网站设置',
//            'url' => \yii\helpers\Url::to(['admin/site/index']),
            'class' => 'active',
        ]
    ];
?>
    <div class="row">
        <div class="col-md-12">
            <div class="block-flat">
                <div class="header">
                    <h4>网站设置</h4>
                </div>
                <div class="content">
                    <form id="siteData" class="form-horizontal group-border-dashed" style="border-radius: 0px;">
                        <input type="hidden" name="id" value="<?php echo !empty($config['id']) ? $config['id'] : ''?>">
                        <input name="<?= Yii::$app->request->csrfParam;?>" type="hidden" value="<?= Yii::$app->request->csrfToken ?>">

                        <div class="form-group" style="padding-bottom: 0px">
                            <label class="col-sm-2 control-label">网站LOGO</label>
                            <div class="col-sm-10">
                                <button type="button" id="upload" class="btn btn-primary"><i class="fa fa-cloud-upload"></i> 选择图片</button>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <img id="logo" src="<?php echo !empty($config['logo']) ? $config['logo'] : '/images/upload.png'?>" class="img-thumbnail"
                                     style="height:128px;">
                                <input type="hidden" name="logo" value="<?php echo !empty($config['logo']) ? $config['logo'] : ''?>">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">标题</label>
                            <div class="col-sm-9">
                                <input type="text" name="title" value="<?php echo !empty($config['title']) ? $config['title'] : ''?>" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">描述</label>
                            <div class="col-sm-9">
                                <textarea name="desc" class="form-control"><?php echo !empty($config['desc']) ? $config['desc'] : ''?></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">ICP备案号</label>
                            <div class="col-sm-9">
                                <input type="text" name="icp" value="<?php echo !empty($config['icp']) ? $config['icp'] : ''?>" class="form-control">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button onclick="saveInfo.saveData()" type="button" class="btn btn-primary"><i class="fa fa-save"></i>保存</button>
                                <button onclick="history.go(-1);" class="btn btn-default"><i class="fa fa-mail-reply"></i>返回</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

<?php $this->beginBlock('footerJsFile')?>
    <script src="/plugins/layui/layui.js"></script>
<?php $this->endBlock()?>


<?php $this->beginBlock('footerJsText')?>
    <script>

        var saveInfo = {
            saveData:function () {
                var data = $("#siteData").serialize();
                ajaxLock = false;
                if (ajaxLock)return false;
                ajaxLock = true;
                $.ajax({
                    type:'POST',
                    dataType:'json',
                    data:data,
                    url:'<?php echo \yii\helpers\Url::to(['admin/site/save'])?>',
                    success:function (resp) {
                        layer.msg(resp.m);
                    },
                    error:function () {
                        console.log("save失败");
                    }
                });
            }
        };

        // 上传封面图相关操作
        layui.use('upload', function(){
            var upload = layui.upload;

            //执行实例
            var uploadInst = upload.render({
                elem: '#upload' //绑定元素
                ,url: '<?php echo \yii\helpers\Url::to(['admin/api/upload/index'])?>' //上传接口
                ,method:'post'//请求方式
                ,data:{
                    '<?php echo Yii::$app->request->csrfParam?>':'<?php echo Yii::$app->request->csrfToken?>',
                    category:'image',
                    action:'config'

                }//额外数据
                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                    layer.load(); //上传loading
                    obj.preview(function(index, file, result){
                        $('#logo').attr('src', result); //图片链接（base64）
                    });
                }
                ,done: function(res){
                    //上传完毕回调
                    $('input[name=logo]').val(res.path);
                    layer.closeAll('loading'); //关闭loading
                }
                ,error: function(){
                    //请求异常回调
                    layer.closeAll('loading'); //关闭loading
                }
            });
        });
    </script>
<?php $this->endBlock()?>